<template>
  <div class="music-list">
    <title-bar :title="title"></title-bar>
    <div class="bg-image" :style="bgStyle" ref="bgImage">
      <div class="filter" ref="filter"></div>
      <div class="play-wrapper" ref="playwrapper">
        <div class="play" v-show="songs.length>0">
          <i class="iconfont icongerenxinxi"></i>
          <span class="text">歌手信息</span>
        </div>
      </div>
    </div>
    <div class="bg-layer" ref="layer"></div>
    <div class="scroll-wrap" ref="listWrap">
      <scroll
        :data="songs"
        class="list"
        :listen-scroll="listenScroll"
        :probe-type="probeType"
        ref="list"
        @scroll="scroll"
      >
        <div class="song-list-wrapper">
          <song-list :songs="songs" @select="selectItem" @playAll="playAllMusic" hideCollect></song-list>
        </div>
      </scroll>
    </div>
  </div>
</template>

<script>
import Scroll from "@/base/scroll/scroll";
import SongList from "@/base/song-list/song-list";
import TitleBar from "@/base/title-bar/title-bar";
import { prefixStyle } from "@/utils/dom";
import { mapActions } from "vuex";
const Rev_HEIGHT = 40;
const transform = prefixStyle("transform");
const backdrop = prefixStyle("backdrop-filter");
import { playListMixin } from "@/common/mixin.js";
export default {
  mixins: [playListMixin],
  props: {
    bgImage: {
      type: String,
      default: ""
    },
    songs: {
      type: Array,
      default: []
    },
    title: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      scrollY: 0
    };
  },

  components: {
    Scroll,
    SongList,
    TitleBar
  },
  computed: {
    bgStyle() {
      return `background-image:url(${this.bgImage})`;
    }
  },
  created() {
    this.probeType = 3;
    this.listenScroll = true;
  },
  mounted() {
    this.imageHeight = this.$refs.bgImage.clientHeight;
    this.minTranslateY = -this.imageHeight + Rev_HEIGHT;
    this.$refs.listWrap.style.top = `${this.imageHeight}px`;
  },
  methods: {
    handlePlayList(playlist) {
      const bottom = playlist.length > 0 ? "60px" : "";
      this.$refs.listWrap.style.bottom = bottom;
      this.$refs.list.refresh();
    },
    routerback() {
      this.$router.back();
    },
    scroll(pos) {
      this.scrollY = pos.y;
    },
    selectItem(item, index) {
      this.selectPlay({
        list: this.songs,
        index: index
      });
    },
    playAllMusic(mode) {
      if (mode == "random") {
        this.randomPlay({
          list: this.songs
        });
      }
    },
    ...mapActions(["selectPlay", "randomPlay"])
  },
  watch: {
    scrollY(newY) {
      let translateY = Math.max(this.minTranslateY, newY);
      let zIndex = 0;
      let scale = 1;
      let blur = 0;
      // 往下拉监听图片放大
      // 获取比例(比例为往下拉的距离除以图片高度)：
      const percent = Math.abs(newY / this.imageHeight);
      if (newY > 0) {
        zIndex = 10;
        scale = 1 + percent;
        this.$refs.bgImage.style[transform] = `scale(${scale})`;
        // this.$refs.bgImage.style["Transform"] = `scale(${scale})`;
        // this.$refs.bgImage.style["webkitTransform"] = `scale(${scale})`;
      } else {
        // 往上拉图片慢慢模糊
        blur = Math.min(20 * percent, 20);
      }
      this.$refs.filter.style[backdrop] = `blur(${blur}px)`;
      // 上拉扩展列表高度
      this.$refs.layer.style[transform] = `translate3d(0,${translateY}px,0)`;
      if (newY < this.minTranslateY) {
        zIndex = 10;
        this.$refs.bgImage.style.paddingTop = 0;
        this.$refs.bgImage.style.height = `${Rev_HEIGHT}px`;
        this.$refs.playwrapper.style.display = "none";
      } else {
        this.$refs.bgImage.style.paddingTop = "70%";
        this.$refs.bgImage.style.height = 0;
        this.$refs.playwrapper.style.display = "block";
      }
      // 设置人物照片层级
      this.$refs.bgImage.style.zIndex = zIndex;
    }
  }
};
</script>

<style lang="less" scoped>
.music-list {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: @color-background;
  .bg-layer {
    position: relative;
    height: 100%;
    background: #222;
  }
  .scroll-wrap {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;

    background: #222;
  }
  .list {
    height: 100%;

    position: relative;
  }
  .back {
    position: absolute;
    top: 0;
    left: 6px;
    z-index: 50;
    .iconfanhui {
      display: block;
      padding: 10px;
      font-size: @font-size-large-x;
      color: @color-theme;
      font-size: 24px;
    }
  }
  .title {
    position: absolute;
    top: 0;
    left: 10%;
    z-index: 40;
    width: 80%;
    .sl;
    text-align: center;
    line-height: 40px;
    font-size: @font-size-large;
    color: @color-text;
  }
  .bg-image {
    position: relative;
    width: 100%;
    height: 0;
    padding-top: 70%;
    transform-origin: top;
    background-size: cover;
    .play-wrapper {
      position: absolute;
      bottom: 20px;
      z-index: 50;
      width: 100%;
      .play {
        box-sizing: border-box;
        width: 135px;
        padding: 7px 0;
        margin: 0 auto;
        text-align: center;
        border: 1px solid @color-theme;
        color: @color-theme;
        border-radius: 100px;
        font-size: 0;
        .icon-play {
          display: inline-block;
          vertical-align: middle;
          margin-right: 6px;
          font-size: @font-size-medium-x;
        }
        .text {
          font-size: @font-size-small;
          height: 16px;
          margin-left: 4px;
          position: relative;
          bottom: 1.5px;
        }
      }
    }
    .filter {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(7, 17, 27, 0.4);
    }
  }
  .bg-layer {
    position: relative;
    height: 100%;
    background: @color-background;
  }
  .list {
    .song-list-wrapper {
      padding: 0;
    }
    // .loading-container {
    //   position: absolute;
    //   width: 100%;
    //   top: 50%;
    //   transform: translateY(-50%);
    // }
  }
}
</style>